##########################################################################
### Table 1. Average Number of Child-to-Parent Support Categories, U.S ###
##########################################################################

load("/Users/Yannan/Desktop/data_us.RData")

library(dplyr)

## create variable recording total number of child-to-parent support categories
data_us$support_cat <- data_us$y1 + data_us$y2 + data_us$y3 + data_us$y4 + data_us$y5

## create categorical variable of parent's age in 1985
data_us$age_cat <- ifelse(data_us$AGE.parent < 41, "<55", 
                          ifelse(data_us$AGE.parent < 46, "55-60", 
                                 ifelse(data_us$AGE.parent < 51, "60-65", 
                                        ifelse(is.na(data_us$AGE.parent), NA, ">65"))))

## generate cross tabulation
data_us %>%
  group_by(SEX.child, SEX.parent) %>%
  summarise(mean = mean(support_cat), n = n())

data_us %>%
  group_by(married.child, SEX.parent) %>%
  summarise(mean = mean(support_cat), n = n())

data_us %>%
  group_by(EDU.child, SEX.parent) %>%
  summarise(mean = mean(support_cat), n = n())

data_us %>%
  group_by(married.parent, SEX.parent) %>%
  summarise(mean = mean(support_cat), n = n())

data_us %>%
  group_by(age_cat, SEX.parent) %>%
  summarise(mean = mean(support_cat), n = n())
